#pragma once


#include "fxcc/core/platform/common/pch.h"
#include "fxcc/core/platform/common/Joystick.h"
#include "fxcc/core/platform/common/Mouse.h"
#include "fxcc/core/platform/common/Keyboard.h"


namespace fxcc
{
	namespace platform
	{
		namespace common
		{


			struct FXCC_API Input
			{
				fxcc::platform::common::Mouse m_Mouse;

				fxcc::platform::common::Keyboard m_Keyboard;

				std::map<int, Joystick> m_Joysticks;

				struct FXCC_API IO
				{
					bool KeyCtrl;
					bool KeyShift;
					bool KeyAlt;
					IO()
						:KeyCtrl(false), KeyShift(false), KeyAlt(false)
					{

					}
				} m_IO;

				IO& GetIO()
				{
					return m_IO;
				};

				std::vector<int> GetJoystickNos();

				bool MouseHasEV(const MouseButton& btn, const ActionType& actionType)
				{
					return m_Mouse.HasEv(btn, actionType);
				}
				bool KeyboardHasEv(const KeyCode& keyCode, const ActionType& actionType)
				{
					return m_Keyboard.HasEv(keyCode, actionType);
				}

				glm::vec2 GetKeyboardAxis() const
				{
					return m_Keyboard.GetAxis();

				}

				void SetJoystickHat(const int jId, int x, int y)
				{
					if (m_Joysticks.find(jId) == m_Joysticks.end())
					{
						return;
					}
					m_Joysticks[jId].SetHatValue(x, y);

				}

				void SetJoystickAxes(const int jId, int index, const float value)
				{
					if (m_Joysticks.find(jId) == m_Joysticks.end())
					{
						return;
					}
					m_Joysticks[jId].SetAxes(index, value);
				}

				void SetJoystickButton(const int jId, JoystickButton btn, ActionType action)
				{
					if (m_Joysticks.find(jId) == m_Joysticks.end())
					{
						return;
					}
					m_Joysticks[jId].KeyCallback(btn, action);

				};

				void StepJoystickTick(const int jId, const int count, unsigned char* btn)
				{
					if (m_Joysticks.find(jId) == m_Joysticks.end())
					{
						return;
					}
					m_Joysticks[jId].SetStates(count, btn);
				}

				void KeyCallback(KeyCode keyCode, ActionType action);

				void CursorPos(int x, int y)
				{
					m_Mouse.SetCursorPos({ x,y });
				};

				void Scroll(int x, int y)
				{
					m_Mouse.SetScroll({ x, y });
				};

				void MouseCallBack(MouseButton mouse, ActionType action);

				void JoysticCallback(int joy, int event, const char* name);

				void Clear()
				{
					m_Mouse.Clear();
					m_Keyboard.Clear();

					for (auto& js : m_Joysticks)
					{
						js.second.Clear();
					}
				}

			};
		}
	}
}